<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Edit</title>
    </h:head>
    <h:body>
        <ui:composition template="/templates/employee_master.xhtml">
            <ui:define name="content">

                <p:panel id="panel" header="Update Account">
                    <p:messages id="messages" />
                    <h:panelGrid columns="3">

                        <h:outputText value="First Name"/>
                        <p:inputText id="name" value="#{loginController.currentEditUser.firstname}"  required="true" requiredMessage="FirstName is required" validatorMessage="FirstName should be of length from 2 to 25 chars" >
                            <f:validateLength for="name" minimum="2" maximum="25"/>
                            <f:validateRequired for="name" />
                        </p:inputText>
                        <p:message for="name"/>

                        <h:outputText value="Last Name"/>
                        <p:inputText id="lastname" value="#{loginController.currentEditUser.lastname}" required="true" requiredMessage="FirstName is required" validatorMessage="FirstName should be of length from 2 to 25 chars" >
                            <f:validateLength for="lastname" minimum="2" maximum="25"/>
                            <f:validateRequired for="lastname"/>
                        </p:inputText>
                        <p:message for="lastname"/>

                        <h:outputText   value="Email" />
                        <p:inputText id="email" value="#{loginController.currentEditUser.email}" required="true" validatorMessage="Invail Email">
                            <f:validateRegex pattern="[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]"  />

                        </p:inputText>
                        <p:message for="email"/>


                        <h:outputText value="Birthday"/>
                        <p:calendar id="birthday" value="#{loginController.currentEditUser.birthday}" pattern="dd/mm/yyyy" effect="drop" mindate="01/01/1990" maxdate="01/01/2012" required="true" />
                        <p:message for="birthday"></p:message>
                        <h:outputText value="Departments: "/>
                        <p:selectOneMenu id="selectDepartment" value="#{loginController.currentEditUser.departmentID}">
                            <f:selectItems value="#{departmentsController.itemsAvailableSelectOne}" var="i" itemLabel="${i.label}" itemValue="#{i.value}"/>
                        </p:selectOneMenu>
                        <p:message for="selectDepartment"/>
                        


                    </h:panelGrid>
                    <f:facet name="footer">
                        <table width="100%">
                            <tr>
                                <td width="30%">
                                    <p:commandButton ajax="false" update="panel, messages" value="Update" action="#{loginController.saveEditAccount()}"/>
                                </td>
                                <td align="right"> 
                                    <p:commandButton ajax="false" immediate="true" action="#{accountsController.prepareList()}" value="List"/> 
                                </td>
                            </tr>
                        </table>

                    </f:facet>
                </p:panel>

            </ui:define>
        </ui:composition>
    </h:body>
</html>

